#ifndef DOMAIN_SERVLET_H
#define DOMAIN_SERVLET_H
#include "IServlet.h"
#include <vector>
class DomainClientServlet : public IServlet {
public:
    virtual void on(SERVLET_STATUS type,std::function<int(ISession *session,void*,int)> handler);
    virtual void request(const void *data,int len);
    virtual void start();
    virtual void wait();
    virtual void stop();
    virtual void onLoad(INode *node);
    virtual void onUnload();
    virtual void onMessage(ISession *session,void* data,int size);
    virtual void onState(SERVLET_STATUS status,ISession *session,int code);
    virtual ~DomainClientServlet();
    virtual void recvthreadLogic(int socket);
private:
    std::string name;
    std::string url;
    void *_client = 0;
    std::map<int,std::vector<std::function<int(ISession *,void*,int)> > >  msgidHandlers;

    void threadLogic();
    void *_thread = NULL;
    bool isRun = true;
     int conn_fd = -1;
};

class DomainServerServlet : public IServlet {
public:
    virtual void on(SERVLET_STATUS type,std::function<int(ISession *session,void*,int)> handler);
    virtual void request(const void *data,int len);
    virtual void start();
    virtual void wait();
    virtual void stop();
    virtual void onLoad(INode *node);
    virtual void onUnload();
    virtual void onMessage(ISession *session,void* data,int size);
    virtual void onState(SERVLET_STATUS status,ISession *session,int code);
    virtual void recvthreadLogic(int socket);
    virtual ~DomainServerServlet();
private:
    std::string name;
    std::string url;
    std::map<int,std::vector<std::function<int(ISession *,void*,int)> > >  msgidHandlers;
    void threadLogic();
    void *_thread = NULL;
    bool isRun = true;
};

#endif //DOMAIN_SERVLET_H